package org.i1510.common.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.i1510.common.bean.PageBean;
import org.i1510.common.dao.ISysInvitationDao;
import org.i1510.common.po.SysInvitation;
import org.i1510.common.service.ISysInvitationService;
import org.i1510.common.utils.BeanUtils;
import org.i1510.common.utils.web.ResultMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("iSysInvitationService")
public class SysInvitationServiceImpl extends BaseServiceImpl implements
		ISysInvitationService {
	@Autowired
	private ISysInvitationDao iSysInvitationDao;

	@Transactional
	public ResultMapper saveAll(List<SysInvitation> list) {

		ResultMapper mapper = ResultMapper.generateFailure();

		List<SysInvitation> listSaved = iSysInvitationDao.save(list);
		
		if (listSaved == null) {
			return null;
		}
		mapper = ResultMapper.generateSuccess();
		mapper.appendResult("baseRtn", listSaved);
		return mapper;
	}

	public ResultMapper save(SysInvitation basePo) {

		ResultMapper mapper = ResultMapper.generateFailure();
		SysInvitation saved = iSysInvitationDao.save(basePo);
		if (saved == null) {
			return null;
		}
		mapper = ResultMapper.generateSuccess();
		mapper.appendResult("baseRtn", saved);
		return mapper;
	}

	public ResultMapper delete(String fdId) {

		ResultMapper mapper = ResultMapper.generateFailure();
		iSysInvitationDao.delete(fdId);
		mapper = ResultMapper.generateSuccess();
		return mapper;
	}

	public SysInvitation findById(String fdId) {
		SysInvitation SysInvitation = iSysInvitationDao.findById(fdId);
		return SysInvitation;
	}

	public List<SysInvitation> findByIds(List<String> fdIds) {
		return (List<SysInvitation>) iSysInvitationDao.findAll(fdIds);
	}

	public List getPage(SysInvitation sysInvitation, PageBean pageBean,Map conditions) {
		Map map = new HashMap();
		// Bean转成Map
		BeanUtils.ObjectCopyMap(sysInvitation, map);
		map.put("intPageIndex", pageBean.getIntPageIndex());
		map.put("intPageSize", pageBean.getIntPageSize());
		map.putAll(conditions);
		List list = this.queryForListBySql("sysInvitationSql.getPage", map);
		return list;
	}

	public int getPageCount(SysInvitation sysInvitation,Map conditions) {
		Map map = new HashMap();
		// Bean转成Map
		BeanUtils.ObjectCopyMap(sysInvitation, map);
		map.putAll(conditions);
		List list = this.queryForListBySql("sysInvitationSql.getPageCount", map);
		return list.size();
	}

}